﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Domain;
using MAF.Windows;

namespace WinFormUI
{
    /// <summary>
    /// 便签式记事板。
    /// </summary>
    public partial class NoteListView : UserControl
    {
        /// <summary>
        /// 构造方法
        /// </summary>
        public NoteListView()
        {
            InitializeComponent();
            
            RefreshList();
        }

        /// <summary>
        /// 刷新列表
        /// </summary>
        public void RefreshList()
        {
            var list = Notepad.Instance.Memo.ShowNotes();

            listMemo.Items.Clear();
            foreach (var note in list)
            {
                var i = listMemo.Items.Add(note.Content);
                var item = listMemo.Items[i];
                item.Tag = note;
                item.Click += new EventHandler(OnListItemClick);
                //item.CheckBox.CheckStateChanged += new EventHandler(Item_CheckStateChanged);
            }
        }

        #region 事件

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnNewButtonClick(object sender, EventArgs e)
        {
            if (null != NewButtonClick)
                NewButtonClick(sender, e);
        }

        /// <summary>
        /// 删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void nlvList_ItemDoubleClick(object sender, EventArgs e)
        {
            ////listView.Remove(((sender as Label).Tag as Note).Id);
            //this.Controls.Remove(sender as Label);
            //Refresh();
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnListItemClick(object sender, EventArgs e)
        {
            if (null != ListItemClick)
                ListItemClick(sender, e);
        }

        /// <summary>
        /// 点击新增按钮
        /// </summary>
        public event EventHandler NewButtonClick;

        /// <summary>
        /// 点击列表中的项
        /// </summary>
        public event EventHandler ListItemClick;

        #endregion
    }
}
